<template>
  <div class="stickBox">
    <div class="box">
      <div class="boxHead">
        <span style="display:block;margin-left: 10px;width: 73px;">楼盘名称</span>
        <span style="margin-left: 24px;">区域</span>
        <span style="margin-left: 24px;">价格(元/m²)</span>
      </div>
      <div v-for="item in stickList" :key="item.id" :chosen="item.chosen" :href="item.href"
        :img="item.img" :position="item.position" :price="item.price" :name="item.name">
        <a :href="item.href" id="boxChosenItem" v-if="item.chosen" @click="choose(item.id)">
          <img :src="item.img" />
          <div class="detail">
            <p class="name">{{item.name}}</p>
            <p>区域：<span class="position">{{item.position}}</span></p>
            <p>价格：<span class="price">{{item.price}}</span></p>
          </div>
        </a>
        <a id="boxItem" :href="item.href" v-else @click="choose(item.id)">
          <p class="name">{{item.name}}</p>
          <p class="position">{{item.position}}</p>
          <p class="price">{{item.price}}</p>
        </a>
      </div>
    </div>
  </div>
</template>

<script>
import { defineComponent, ref } from 'vue'
export default defineComponent({
  setup () {
    const stickList = ref([
      {
        id: 1,
        chosen: true,
        img: '',
        name: '融创·翔龙 | 廣府壹號',
        position: '天河',
        price: '59999'
      },
      {
        id: 2,
        chosen: false,
        img: '',
        name: 'addddddddd',
        position: '从化',
        price: '49000'
      },
      {
        id: 3,
        chosen: false,
        img: '',
        name: 'aaaaaaaaaaaaa',
        position: '花都',
        price: '49000'
      },
      {
        id: 4,
        chosen: false,
        img: '',
        name: 'aaaaaaaaaaaaaaaaaaaa',
        position: '白云',
        price: '49000'
      }
    ])
    const choose = (id) => {
      stickList.value.forEach(item => {
        if (item.id === id) {
          item.chosen = true
        } else {
          item.chosen = false
        }
      })
    }
    return {
      stickList,
      choose
    }
  }
})
</script>

<style lang="less" scoped>
.stickBox {
  position: absolute;
  right: 0;
  width: 228px;
  height: 100%;
  .box {
    position: sticky;
    top: 0;
    width: 228px;
    height: 430px;
    border: 1px solid #ededed;
    .boxHead {
      display: flex;
      align-items: center;
      width: 100%;
      height: 28px;
      background: #f5f5f5;
      span {
        font-family: 'HarmonyOS Sans SC';
        font-style: normal;
        font-weight: 400;
        font-size: 12px;
        line-height: 14px;
        color: #333333;
      }
    }
    #boxItem {
      display: flex;
      padding-top: 12px;
      padding-bottom: 12px;
      p {
        display: block;
        margin-left: 24px;
        font-family: 'HarmonyOS Sans SC';
        font-style: normal;
        font-weight: 400;
        font-size: 12px;
        line-height: 14px;
        color: #333333;
      }
      .name {
        width: 73px;
        margin-left: 10px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
      }
    }
    #boxChosenItem {
      display: flex;
      align-items: center;
      width: 228px;
      height: 60px;
      background: #f5f5f5;
      img {
        height: 100%;
        width: 80px;
      }
      .detail {
        margin-left: 4px;
        .name {
          display: block;
          width: 111px;
          overflow: hidden;
          text-overflow: ellipsis;
          white-space: nowrap;
          color: #333;
        }
        p {
          margin-bottom: 4px;
          font-family: 'HarmonyOS Sans SC';
          font-style: normal;
          font-weight: 400;
          font-size: 12px;
          line-height: 14px;
          color: #999;
        }
        span {
          color: #333;
        }
      }
    }
  }
}
</style>
